package leetcode;

import java.util.Arrays;

public class CanTransform {
    public static void main(String[] args) {
        String start = "RXXLRXRXL", result = "XRLXXRRLX";
        System.out.println(canTransform(start, result));
    }
    public static boolean canTransform(String start, String result) {
        String[] arr = new String[start.length()];
        // 将字符串转为数组
        for(int i = 0;i<start.length();i++){
            arr[i] = start.charAt(i) + "";
        }
        int left = 0;
        int right = 1;
        while (left < start.length()&&right < start.length()) {
            // 双指针遍历01，每次取最近两个
            if((arr[left]+arr[right]).equals("XL")){
                System.out.println(arr[left]+arr[right]);
                arr[left] = "L";
                arr[right] = "X";
                left=left+2;
                right = right + 2;
            }else if((arr[left]+arr[right]).equals("RX")){
                System.out.println(arr[left]+arr[right]);
                arr[left] = "X";
                arr[right] = "R";
                left=left+2;
                right = right + 2;
            }else {
                left++;
                right++;
            }
        }
        System.out.println(Arrays.toString(arr));
        // 最后判断数组是否和result一致
        for(int i = 0;i<arr.length;i++){
            if(!arr[i].equals(result.charAt(i) + "")){
                return false;
            }
        }
        return true;
    }
}
